﻿/*-----------------------------------------------
// File: ParticleData.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;

public class ParticleData {
    public string particleId;
    public string resUrl;
    public float duration;
    public bool IsLoop;

    public string bindBone;

    public Vector3 offset;

    public ParticleType pt;

    public void SetData(ParticleData pd)
    {
        particleId = pd.particleId;
        resUrl = pd.resUrl;
        duration = pd.duration;
        IsLoop = pd.IsLoop;
        bindBone = pd.bindBone;
        offset = pd.offset;
        pt = pd.pt;
    }

    public static ParticleData CreateCommonParticleData(string id)
    {
        var dict = Dict.Blo.DictParticleBlo.GetCommonParticle(id);
        if (dict != null)
        {
            var data = new ParticleData();
            data.particleId = id;
            data.resUrl = dict.ResourcePath;
            data.duration = (float)dict.Duration;
            data.IsLoop = dict.Duration == 0 ? true : false;
            data.pt = ParticleType.NORMAL;
            return data;
        }
        return null;
    }

    public static ParticleData CreateParticleData(string id) {
        var dict = Dict.Blo.DictParticleBlo.GetParticle(id);
        if (dict != null) {
            var data = new ParticleData();
            data.particleId = id;
            data.resUrl = dict.ResourcePath;
            data.duration = (float)dict.Duration;
            data.IsLoop = dict.IsLoop == 0 ? false : true;
            data.pt = ParticleType.NORMAL;
            return data;
        }
        return null;
    }

    public static ParticleData CreateParticleData(string id, string bindBone)
    {
        var dict = Dict.Blo.DictParticleBlo.GetParticle(id);
        if (dict != null)
        {
            if (dict.ResourcePath.Contains("ui"))
            {
                ParticleData data = new ParticleData();
                data.particleId = id;
                data.resUrl = dict.ResourcePath;
                data.duration = (float)dict.Duration;
                data.IsLoop = dict.IsLoop == 0 ? false : true;
                data.bindBone = bindBone;
                data.pt = ParticleType.BIND_UI;
                return data;
            }
            else
            {
                var data = new ParticleData();
                data.particleId = id;
                data.resUrl = dict.ResourcePath;
                data.duration = (float)dict.Duration;
                data.IsLoop = dict.IsLoop == 0 ? false : true;
                data.bindBone = bindBone;
                data.pt = ParticleType.BIND_BONE;
                return data;
            }
        }
        return null;
    }

    public static ParticleData CreateParticleData(string id, Vector3 offset)
    {
        var dict = Dict.Blo.DictParticleBlo.GetParticle(id);
        if (dict != null)
        {
            var data = new ParticleData();
            data.particleId = id;
            data.resUrl = dict.ResourcePath;
            data.duration = (float)dict.Duration;
            data.IsLoop = dict.IsLoop == 0 ? false : true;
            data.offset = offset;
            data.pt = ParticleType.BASE_OFFSET;
            return data;
        }
        return null;
    }

}


public enum ParticleType
{
    NORMAL,
    BIND_BONE,
    BASE_OFFSET,
    BIND_UI,
}
